package com.itheima.day08.studentTest;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        Student s1 = new Student("小王", 18, 90);
        Student s2 = new Student("小王", 18, 99);
        Student s3 = new Student("小王", 19, 90);
        Student s4 = new Student("小CHENG", 18, 80);
//        Set<Student> set = new TreeSet<>(( o1,o2) ->o1.getAge() - o2.getAge());
        Set<Student> set = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if(o2.getAge() == o1.getAge()){
                    return Double.compare(o1.getScore(), o2.getScore());
                }else{
                    return o2.getAge()-o1.getAge();
                }
            }
        });
        //TreeSet<Student> set = new TreeSet<>();默认升序，当传入的对象实现Comparable接口时，按照对象中的compareTo方法进行排序
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        System.out.println(set);
    }
}
